<style type="text/css" media="all">
    /*.layui-table td{ text-align:center!important; line-height:65px;}
    .layui-table tr{height:65px;line-height:65px;}*/
</style>

<div class="layui-col-md12">
    <form  class="layui-form">
    <table class="layui-table">
        <tbody>
            <tr>
                <td>账号</td>
                <td>
                    <input type="text" name="account" lay-verify="title" autocomplete="off" placeholder="请输入账号"  class="layui-input" value="{$config.account|default=''}">
                </td>
            </tr>
            <tr>
                <td>密码</td>
                <td>
                    <input type="text" name="account_pass" lay-verify="title" autocomplete="off" placeholder="请输入密码" class="layui-input" value="{$config.account_pass|default=''}">
                </td>
            </tr>
            <tr>
                <td>短信模板列表</td>
                <td>
                    <table  class="layui-table">
                        <tr>
                            <td>模板标识</td>
                            <td>模板名称</td>
                            <td>签名</td>
                            <td>模板号</td>
                            <td>备注</td>
                            <td width="60">操作</td>
                        </tr>
                        <?php $mblist = isset( $config [ 'mb_list' ] ) ? $config  ['mb_list'] : []; ?>
                        <volist name="$mblist" id="vo">
                        <tr class="xx">
                            
                            <td>{$vo.mb_name|default=''}</td>
                            <td>{$vo.mb_title|default=''}</td>
                            <td>{$vo.mb_sign|default=''}</td>
                            <td>{$vo.mb_number|default=''}</td>
                            <td>{$vo.mb_remark|default=''}</td>
                            <td>
                                <a style="color:#1EBD9E;" href="#" class="btn-edit-mb-mc">编辑</a>
                                <a style="color:#1EBD9E;" href="#" data-tag="{$vo.mb_name|default=''}" class="btn-delete-mb-mc">删除</a>
                            </td>
                        </tr>
                        </volist>
                    </table>
                </td>
            </tr>
            <tr>
                <td>短信模板</td>
                <td>
                    <blockquote class="layui-elem-quote" style="margin-top:10px;">添加格式: verfiy_code#验证码#签名#SMS_20021321#模板变量: code (批量添加请换行)</blockquote>
                    <textarea name="mb_list"  class="layui-textarea" rows="4" cols="40" placeholder="格式: verfiy_code#验证码#签名#SMS_20021321#模板变量: code (批量添加请换行)"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center;">
                    <button type="button" class="layui-btn layui-btn-sm " lay-submit lay-filter="mountain_cattle_setconfig">保存配置</button>
                </td>
            </tr>
        </tbody>
    </table>
    </form>
</div>
<!-- 自动加载js -->
<div style="display:none;" class="__is_autoload_js__">
    ;(function(){
        var form = layui.form;
        

        //监听提交
        form.on('submit(mountain_cattle_setconfig)', function(data){
            $.ajax({
                url:'{:cmf_plugin_url("Sms://mountain_cattle/saveConfig")}',
                data:{data:data.field},
                method:'post',
                success:function(res){
                    layer.msg( res.message , { time:1000 , icon:(res.code ==200 )?1:5 } , function(){
                        if ( res.code == 200 ){
                            window.location.reload();
                        }
                    } );
                }
            });
            return false;
        });
        
        $(document).on( 'click' , '.btn-edit-mb-mc' , function(){
        
            let tr = $(this).parents('.xx');
            let mb_name = tr.find('td:eq(0)').text();
            let mb_title = tr.find('td:eq(1)').text();
            let mb_sign = tr.find('td:eq(2)').text();
            let mb_number = tr.find('td:eq(3)').text();
            let mb_remark = tr.find('td:eq(4)').text();
            
            var val = mb_name+"#"+mb_title+"#"+mb_sign+"#"+mb_number+"#"+mb_remark;
            layer.prompt({
                formType: 2,
                value: val,
                title: mb_title+"模板修改",
                area: ['300px', '50px'] //自定义文本域宽高
                }, function(value, index, elem){
                    $.post( '{:cmf_plugin_url("Sms://mountain_cattle/savemb")}', {mblist:value} , function( res){
                        layer.msg( res.message , { icon:res.code==200?1:6 , time:800 } ,function(){
                            if( res.code ==200 ){
                                window.location.reload();
                            }
                        } );
                    } );
            });
        } );
        
        
        $(document).on( 'click' , '.btn-delete-mb-mc' , function(){
            let key = $( this ).data( 'tag' );
            let _this = $( this );
            layer.confirm( '删除模板后可能会影响正常发送短信,请谨慎操作!确定要删除此模板吗?' , { icon:5 ,title:"删除提醒"} , function(){
                
                $.post( '{:cmf_plugin_url("Sms://mountain_cattle/deletemb") }' , {key:key} , function( res ){
                    layer.msg( res.message , { icon: res.code==200 ?1:5 , time:800 } , function( ){
                        if( res.code == 200 ){
                            _this.parents('.xx').remove();
                        }
                        layer.closeAll();
                    } );
                });
            } );
            
            
            
        } );
        
    })();
</div>
<!-- 自动加载js -->
